﻿<extend name="./_base"/>
<block name="css">

</block>
<block name="content">

        <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 游戏管理 <span
                class="c-gray en">&gt;</span> 游戏列表 <a class="btn btn-success radius r"
                                                      style="line-height:1.6em;margin-top:3px"
                                                      href="javascript:location.reload();" title="刷新"><i
                class="Hui-iconfont">&#xe68f;</i></a></nav>
        <div class="page-container">
            <div class="cl pd-5 bg-1 bk-gray mt-20 mb-20"><span class="l"> <a
                    href="javascript:;" onclick="add()"
                    class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加新游戏</a></span></div>
            <table id="game-list" class="table table-border table-bordered table-bg">
                <thead>
                <tr>
                    <th scope="col" colspan="9">游戏列表</th>
                </tr>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="40">ID</th>
                    <th>游戏名称</th>
                    <th width="150">添加时间</th>
                    <th width="80">状态</th>
                    <th width="200">操作</th>
                </tr>
                </thead>
            </table>
        </div>
</block>

<block name="script">
    <script src="__PUBLIC__/Lib/datatables/js/jquery.dataTables.js"></script>
    <script>
        $('#game-list').dataTable({
            order: [[1, 'desc']],
            processing: true,
            serverSide: true,
            ajax: {
                url: ''
            },
            columns: [
                {
                    data: 'id',
                    render: function (data) {
                        return '<input type="checkbox" name="id" value="' + data + '">'
                    },
                    className: 'text-c',
                    orderable: false
                },
                {
                    data: 'id',
                    className: 'text-c',
                },
                {
                    data: 'name',
                    className: 'text-c',
                },
                {
                    data: 'time',
                    className: 'text-c',
                },
                {
                    data: 'status',
                    render: function (data, type, row, meta) {
                        var render;
                        switch (parseInt(data)) {
                            case 0:
                                render = '<label class="label radius">已禁用</label>';
                                break;
                            case 1:
                                render = '<label class="label label-success radius">已启用</label>';
                                break;
                            default:
                                render = '<label class="label label-danger radius">未知状态</label>';
                                break;
                        }
                        return render;
                    },
                    className: 'text-c'
                },
                {
                    render: function (data, type, row, meta) {
                        var render;
                        switch (parseInt(row.status)) {
                            case -1:
                                render = '<a href="javascript:void(0);" onclick="start(' + row.id + ')" title="启用"><i class="Hui-iconfont Hui-iconfont-shangjia"></i></a>';
                                break;
                            case 0:
                                render = '<a href="javascript:void(0);" onclick="start(' + row.id + ')" title="启用"><i class="Hui-iconfont Hui-iconfont-shangjia"></i></a>';
                                render += '<a class="ml-5" href="javascript:void(0);" onclick="del(' + row.id + ')" title="删除"><i class="Hui-iconfont Hui-iconfont-del3"></i></a>';
                                break;
                            case 1:
                                render = '<a href="javascript:void(0);" onclick="stop(' + row.id + ')" title="停用"><i class="Hui-iconfont Hui-iconfont-xiajia"></i></a>';
                                break;
                        }

                        render += '<a class="ml-5" href="javascript:void(0);" onclick="edit(' + row.id + ')" title="修改信息"><i class="Hui-iconfont Hui-iconfont-edit"></i></a>';
//                        render += '<a class="ml-5" href="javascript:void(0);" onclick="show_rate(' + row.id + ')" title="查看操作日志"><i class="Hui-iconfont Hui-iconfont-log"></i></a>';
                        return render;

                    },
                    "orderable": false,
                    "className": "text-c"
                }

            ]

        })

        function del(id) {
            send(id, 'del')
        }
        //启用
        function start(id) {
            send(id, 'start')
        }
        //停用
        function stop(id) {
            send(id, 'stop')
        }
        //执行
        function send(id, status) {
            $.ajax({
                type: 'GET',
                url: '{:U(gameStatus)}',
                data: {id: id, status: status},
                dataType: 'json',
                success: function (result) {
                    if (result.status == 1) {
                        layer.alert(result.info, {icon: 6}, function () {
                            location.reload();
                        });
                    } else {
                        layer.alert(result.info, {icon: 5});
                    }
                }

            })
        }
        function remove(id) {
            $.ajax({
                type: 'GET',
                url: '{:U(gameStatus)}',
                data: {id: id, status: status},
                dataType: 'json',
                success: function (result) {
                    if (result.status == 1) {
                        layer.alert(result.info, {icon: 6}, function () {
                            location.reload();
                        });
                    } else {
                        layer.alert(result.info, {icon: 5});
                    }
                }

            })
        }


        function add(title, url, w, h) {
            layer_show("添加", '{:U(gameEdit)}', 480, 360);
        }
        function edit($id) {
            layer_show("修改", '{:U(gameEdit)}?id=' + $id, 480, 360);
        }

    </script>
</block>



